package com.ticket.sass.admin.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.annotation.Loggable;
import com.ticket.sass.admin.annotation.Module;
import com.ticket.sass.admin.business.CommodityCloudPrinterBusiness;
import com.ticket.sass.admin.dto.input.printer.CommodityCloudPrinterAddInput;
import com.ticket.sass.admin.dto.input.printer.CommodityCloudPrinterListInput;
import com.ticket.sass.admin.dto.input.printer.CommodityCloudPrinterUpdInput;
import com.ticket.sass.admin.dto.output.printer.CommodityCloudPrinterListOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author ywb
 * @date 2024-04-08 14:37
 */
@RestController
@AllArgsConstructor
@ApiSupport(order = 005)
@Api(tags = {"打印机数据-模块"})
@RequestMapping("/commodities/printers")
public class CommodityCloudPrinterController {
    final CommodityCloudPrinterBusiness business;
    
    @GetMapping
    @ApiOperation("列表")
    public ResultModel<PageModel<CommodityCloudPrinterListOutput>> list(
        @Valid CommodityCloudPrinterListInput input
    ) {
        return ResultModel.success(
            business.list(input)
        );
    }
    
    @PostMapping
    @ApiOperation("新增")
    @Loggable(module = Module.COMMODITY_DISPATCH, desc = "新增打印机")
    public ResultModel<String> add(
        @RequestBody @Valid CommodityCloudPrinterAddInput input
    ) {
        business.add(input);
        return ResultModel.success();
    }
    
    @PutMapping
    @ApiOperation("修改打印机")
    @Loggable(module = Module.COMMODITY_DISPATCH, desc = "修改打印机")
    public ResultModel<String> upd (
        @RequestBody @Valid CommodityCloudPrinterUpdInput input
    ) {
        business.upd(input);
        return ResultModel.success();
    }
}
